package com.systemic.controller;

import com.systemic.core.ResponseResult;
import com.systemic.pojo.Dynamic;
import com.systemic.pojo.EmotionLog;
import com.systemic.service.EmotionLogService;
import com.systemic.vo.PageVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName: EmotionLogController
 * @Description:
 * @Author:
 * @CreateTime: 2024-01-22 17:32
 * @Version:
 **/
@RestController
@RequestMapping("/emotionLog")
public class EmotionLogController {

    @Resource
    private EmotionLogService emotionLogService;

    /**
     * 新增
     * @param emotionLog
     * @return
     */
    @PostMapping("/add")
    public ResponseResult<String> add(@RequestBody EmotionLog emotionLog){
        int row = 0;
        if (emotionLog!=null){
            row = emotionLogService.add(emotionLog);
        }
        return row!=0 ? ResponseResult.success("新增成功") : ResponseResult.failed("新增失败");
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @GetMapping("/deleteList/{ids}")
    public ResponseResult<String> deleteList(@PathVariable("ids") Integer[] ids){
        int row = emotionLogService.deleteList(ids);
        return row != 0 ? ResponseResult.success("删除成功！") : ResponseResult.failed("删除失败");
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @GetMapping("/delete/{id}")
    public ResponseResult<String> delete(@PathVariable("id") Integer id){
        int row = emotionLogService.delete(id);
        return row != 0 ? ResponseResult.success("删除成功") : ResponseResult.failed("删除失败");
    }

    /**
     * 修改
     * @param emotionLog
     * @return
     */
    @PostMapping("/update")
    public ResponseResult<String> update(@RequestBody EmotionLog emotionLog){
        int row = 0;
        if (emotionLog!=null){
            row = emotionLogService.update(emotionLog);
        }
        return row!=0 ? ResponseResult.success("修改成功") : ResponseResult.failed("修改失败");
    }

    /**
     * 分页查询
     * @param pageVo
     * @return
     */
    @PostMapping("/selectList")
    public ResponseResult<List<EmotionLog>> selectList(@RequestBody PageVo pageVo){
        List<EmotionLog> emotionLogs = emotionLogService.selectList(pageVo);
        return ResponseResult.success(emotionLogs);
    }

    /**
     * 指定查询
     * @param id
     * @return
     */
    @GetMapping("/select/{id}")
    public ResponseResult<EmotionLog> select(@PathVariable("id") Integer id){
        EmotionLog emotionLog = emotionLogService.selectById(id);
        return emotionLog != null ? ResponseResult.success(emotionLog) : ResponseResult.failed("没有查询到相关信息");
    }

}
